package com.zx.deploy.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zx.deploy.common.exception.BusinessException;
import com.zx.deploy.config.DeployConfig;
import com.zx.deploy.model.Users;
import com.zx.deploy.service.UserService;

/**
 * 用户管理
 * @author jbyu
 *
 */
@Service
public class UserServiceImpl implements UserService {
	
	/**
	 * 环境变量
	 */
	@Autowired
	protected DeployConfig config;
	
	
	/**
	 * 登录方法
	 * @param psd
	 * @param loginid
	 * @return
	 */
	public Users login(String psd,String loginid) {
		List<Users> data = config.getUserlist();
		Users user = null;
		for (Users u : data) {
			boolean match = u.getUsername().equals(loginid) && u.getPwd().equals(psd);
			if (match) {
				user = u;
				break;
			}
		}
		if (user == null) {
			throw new BusinessException("用户名或密码错误，请重新登录！");
		}
		return user;
	}

}
